import { display, Size } from "@kit.ArkUI"
import { Log } from "./Log"

const TAG = 'PermissionPanelSizeUtils'

export class PermissionPanelSizeUtils {
  static ins: PermissionPanelSizeUtils = null

  static getIns() {
    if (!PermissionPanelSizeUtils.ins) {
      PermissionPanelSizeUtils.ins = new PermissionPanelSizeUtils()
    }
    return PermissionPanelSizeUtils.ins
  }


  // 弹窗页面的缩放比例
  getZoomRatio(): number {
    if (this.getScreenSize().width > this.getScreenSize().height) {
      return this.getRealSize().width / this.getScreenSize().width
    } else {
      return this.getRealSize().width / this.getScreenSize().width - 0.3
    }
  }

  // 屏幕的尺寸
  getScreenSize(): Size {
    return {
      width: display.getDefaultDisplaySync().width,
      height: display.getDefaultDisplaySync().height
    }
  }

  // 实际显示的尺寸大小
  getRealSize(): Size {
    if (this.getScreenSize().width > this.getScreenSize().height) {
      return this.calculatedSize(1200, 512, 1920, 1080)
    } else {
      return this.calculatedSize(950, 450, 1080, 1920)
    }
  }

  // 竖屏下面板的的实际尺寸
  private calculatedSize(ux_panel_width, ux_panel_height, ux_screen_width, ux_screen_height): Size {
    // 设计图的长宽比
    let original_proportion = ux_panel_width / ux_panel_height
    Log.info(TAG, `PortraitScreen original_proportion = ${original_proportion}`);

    // 设计图的总宽度与设计图弹窗的宽度比例
    let screenToUx = ux_screen_width / ux_panel_width
    Log.info(TAG, `PortraitScreen screenToUx = ${original_proportion}`);

    // 当前屏幕的长宽
    let screenWidth = this.getScreenSize().width
    let screenHeight = this.getScreenSize().height
    Log.info(TAG, `PortraitScreen screenWidth = ${screenWidth},  screenHeight = ${screenHeight}`);

    // 实际的尺寸
    let actual_width = screenWidth / screenToUx
    let actual_height = actual_width / original_proportion
    Log.info(TAG, `PortraitScreen actual_width = ${actual_width},  actual_height = ${actual_height}`);

    return {
      width: actual_width,
      height: actual_height
    }
  }
}